package com.huawei.hianalytics.ab.bc.gh;

import android.text.TextUtils;
import com.huawei.hianalytics.ab.bc.ef.ab;

public class bc {
    private static bc ab;
    private String bc;
    private String cd;

    public static bc ab() {
        if (ab == null) {
            de();
        }
        return ab;
    }

    private boolean ab(String str) {
        ab.bc("RootKeyManager", "refresh sp aes key");
        String bc = com.huawei.hianalytics.ab.bc.ab.bc.ab().ab(com.huawei.hianalytics.ab.bc.ab.bc.ab.AES).bc(fg(), str);
        if (TextUtils.isEmpty(bc)) {
            ab.bc("RootKeyManager", "refreshLocalKey(): encrypted key is empty");
            return false;
        }
        com.huawei.hianalytics.ab.bc.ij.ab.ab(com.huawei.hianalytics.ab.ab.bc.ik(), "Privacy_MY", "PrivacyData", bc);
        com.huawei.hianalytics.ab.bc.ij.ab.ab(com.huawei.hianalytics.ab.ab.bc.ik(), "Privacy_MY", "flashKeyTime", System.currentTimeMillis());
        return true;
    }

    private static synchronized void de() {
        synchronized (bc.class) {
            if (ab == null) {
                ab = new bc();
            }
        }
    }

    private String ef() {
        String bc = com.huawei.hianalytics.ab.bc.ij.ab.bc(com.huawei.hianalytics.ab.ab.bc.ik(), "Privacy_MY", "PrivacyData", "");
        com.huawei.hianalytics.ab.bc.ab.bc ab = com.huawei.hianalytics.ab.bc.ab.bc.ab();
        if (TextUtils.isEmpty(bc)) {
            bc = ab.bc(com.huawei.hianalytics.ab.bc.ab.bc.ab.AES);
            ab(bc);
            return bc;
        }
        Object ab2 = ab.ab(com.huawei.hianalytics.ab.bc.ab.bc.ab.AES).ab(fg(), bc);
        if (!TextUtils.isEmpty(ab2)) {
            return ab2;
        }
        bc = ab.bc(com.huawei.hianalytics.ab.bc.ab.bc.ab.AES);
        ab(bc);
        return bc;
    }

    private String fg() {
        if (TextUtils.isEmpty(this.cd)) {
            this.cd = new ab().ab();
        }
        return this.cd;
    }

    public void bc() {
        String bc = com.huawei.hianalytics.ab.bc.ab.bc.ab().bc(com.huawei.hianalytics.ab.bc.ab.bc.ab.AES);
        if (ab(bc)) {
            this.bc = bc;
        }
    }

    public String cd() {
        if (TextUtils.isEmpty(this.bc)) {
            this.bc = ef();
        }
        return this.bc;
    }
}
